package com.iot.web.controller.device;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.iot.device.domain.GasEvent;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.iot.common.annotation.Log;
import com.iot.common.core.controller.BaseController;
import com.iot.common.core.domain.AjaxResult;
import com.iot.common.enums.BusinessType;
import com.iot.device.service.IGasEventService;
import com.iot.common.utils.poi.ExcelUtil;
import com.iot.common.core.page.TableDataInfo;

/**
 * 燃气事件Controller
 * 
 * @author iot
 * @date 2023-04-14
 */
@RestController
@RequestMapping("/device/gasEvent")
public class GasEventController extends BaseController
{
    @Autowired
    private IGasEventService gasEventService;

    /**
     * 查询燃气事件列表
     */
    @PreAuthorize("@ss.hasPermi('device:gasEvent:list')")
    @GetMapping("/list")
    public TableDataInfo list(GasEvent gasEvent)
    {
        startPage();
        List<GasEvent> list = gasEventService.selectGasEventList(gasEvent);
        return getDataTable(list);
    }

    /**
     * 导出燃气事件列表
     */
    @PreAuthorize("@ss.hasPermi('device:gasEvent:export')")
    @Log(title = "燃气事件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GasEvent gasEvent)
    {
        List<GasEvent> list = gasEventService.selectGasEventList(gasEvent);
        ExcelUtil<GasEvent> util = new ExcelUtil<GasEvent>(GasEvent.class);
        util.exportExcel(response, list, "燃气事件数据");
    }

    /**
     * 获取燃气事件详细信息
     */
    @PreAuthorize("@ss.hasPermi('device:gasEvent:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(gasEventService.selectGasEventById(id));
    }

    /**
     * 新增燃气事件
     */
    @PreAuthorize("@ss.hasPermi('device:gasEvent:add')")
    @Log(title = "燃气事件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GasEvent gasEvent)
    {
        return toAjax(gasEventService.insertGasEvent(gasEvent));
    }

    /**
     * 修改燃气事件
     */
    @PreAuthorize("@ss.hasPermi('device:gasEvent:edit')")
    @Log(title = "燃气事件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GasEvent gasEvent)
    {
        return toAjax(gasEventService.updateGasEvent(gasEvent));
    }

    /**
     * 删除燃气事件
     */
    @PreAuthorize("@ss.hasPermi('device:gasEvent:remove')")
    @Log(title = "燃气事件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gasEventService.deleteGasEventByIds(ids));
    }
}
